package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.constant.ExtraName;
import com.shaoshaohuo.app.entity.MyPriceEntity.MyPrice;
import com.shaoshaohuo.app.ui.GrabOrderActivity;
import com.shaoshaohuo.app.utils.AreaUtil;
import com.shaoshaohuo.app.utils.StringHelper;

import java.util.List;

/**
 * 我的报价状态 1  待报价
 */
public class MyPriceWatingAdapter extends MyBaseAdapter<MyPrice> {

    public MyPriceWatingAdapter(Context ctx, List<MyPrice> list, boolean flag) {
        super(ctx, list, flag);
    }

    @Override
    public View getView(final int pos, View view, ViewGroup group) {
        if (view == null) {
            view = View.inflate(context, R.layout.item_my_price_1, null);
        }

        MyPrice myPrice = list.get(pos);
        ViewHolder holder = ViewHolder.getHolder(view);

        holder.ll_price_set.setVisibility(View.GONE);
        holder.ll_price.setVisibility(View.GONE);
//        holder.ll_received_price.setVisibility(View.GONE);

        holder.tv_name.setText(myPrice.ordername);
        holder.tv_num.setText(myPrice.shippweight);
        holder.tv_start_time.setText(myPrice.origintime);
        holder.tv_start_ad.setText(AreaUtil.getAreaFullname(myPrice.origincityid)+myPrice.originaddress);
        holder.tv_end_ad.setText(AreaUtil.getAreaFullname(myPrice.receivecityid)+myPrice.receiveaddress);
        holder.tv_end_time.setText(myPrice.receivetime);
        holder.b_go_price.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GrabOrderActivity.class);
                intent.putExtra(ExtraName.orderid, list.get(pos).orderid);
                context.startActivity(intent);
            }
        });

        return view;
    }

    static class ViewHolder {

        public TextView tv_name;
        public TextView tv_num;
        public TextView tv_start_time;
        public TextView tv_start_ad;
        public TextView tv_end_ad;
        public TextView tv_end_time;
        public TextView b_go_price;
        public LinearLayout ll_price;
        public TextView tv_price;
        public LinearLayout ll_price_set;
        public TextView b_modify_price;
        public TextView b_delete_price;
//        public LinearLayout ll_received_price;
//        public TextView tv_received_price_num;


        private ViewHolder(View view) {
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            tv_num = (TextView) view.findViewById(R.id.tv_num);
            tv_start_time = (TextView) view.findViewById(R.id.tv_start_time);
            tv_start_ad = (TextView) view.findViewById(R.id.tv_start_ad);
            tv_end_ad = (TextView) view.findViewById(R.id.tv_end_ad);
            tv_end_time = (TextView) view.findViewById(R.id.tv_end_time);

            b_go_price = (TextView) view.findViewById(R.id.b_go_price); // 1 待报价

            ll_price = (LinearLayout) view.findViewById(R.id.ll_price);// 2 已提交的报价
            tv_price = (TextView) view.findViewById(R.id.tv_price);
            ll_price_set = (LinearLayout) view.findViewById(R.id.ll_price_set);
            b_modify_price = (TextView) view.findViewById(R.id.b_modify_price);
            b_delete_price = (TextView) view.findViewById(R.id.b_delete_price);

//            ll_received_price = (LinearLayout) view.findViewById(R.id.ll_received_price);// 5 已收到的报价
//            tv_received_price_num = (TextView) view.findViewById(R.id.tv_received_price_num);

            view.setTag(this);
        }

        public static ViewHolder getHolder(View convertView) {
            return (ViewHolder) (convertView.getTag() != null ? convertView.getTag() : new ViewHolder(convertView));
        }
    }
}
